#include<bits/stdc++.h>
using namespace std;
signed main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);   
    int T,ans=0,Ss=0,t_s=0,t=0,wy=0,number=0;
    bool t_f=false;
    cin >>T;
    for(int i=1;i<=T;i++){
        int n,m,L,V;
        int w[L]={0};
        cin >>n>>m>>L>>V;
        int d[n],u[n],a[n],p[m];
        for(int j=0;j<n;j++){
            cin >>d[j]>>u[j]>>a[j];
        }
        for(int j=0;j<m;j++){
            cin >>p[j];
            w[p[j]]=1;
        }
        for(int j=0;j<n;j++){
            if(a[j]==0&&u[j]<=V){
                t_f=false;
            }else{
                t_f=true; 
            }
            while(t_f!=true){
                t_s=u[j]+a[j]*t;
                wy=u[j]*t+0.5*a[j]*t*t;
                Ss=sqrt(pow(u[j],2)+2*a[j]*t_s);
                for(int k=0;k<m;k++){
                    if(p[k]>=d[j]){
                        if(Ss>V){
                            ans++;
                            w[p[k]]++;
                        }
                    }
                }
            }   
            if(t_f==true){   
                ans++;   
            }   
            for(int i=0;i<m;i++){
                if(w[p[i]]>1){
                number++;
                }
            }
        }   
    }   
    cout<<ans<<endl;
    cout<<number<<endl;
    fclose(stdin);   
    fclose(stdout);  
    return 0;
}